home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4137 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: news.interlog.com!news
  2. From: huw@interlog.com (Huw Leonard)
  3. Newsgroups: comp.os.ms-windows.programmer.tools.mfc,comp.os.ms-windows.apps.compatibility.win95,comp.lang.c++
  4. Subject: Re: HELP - CString conversion?
  5. Date: 28 Jan 1996 05:13:34 GMT
  6. Organization: InterLog Internet Services
  7. Message-ID: <4ef0lu$346@steel.interlog.com>
  8. References: <NEWTNews.16531.822443361.Postmaster@Jerusalem.netvision.net.il>
  9. NNTP-Posting-Host: huw.interlog.com
  10. X-Newsreader: WinVN 0.99.3
  11.  
  12. In article <NEWTNews.16531.822443361.Postmaster@Jerusalem.netvision.net.il>, 
  13. iti@Jerusalem.netvision.net.il says...
  14. >
  15. >When I try to read the text from a Edit Control (IDC_EDIT1) with the
  16. >following code:
  17. >
  18. >--------------------------------------------------------------
  19. >CString callBuf;
  20. >int msgLen = GetDlgItemText(IDC_EDIT1, callBuf, sizeof(callBuf));
  21. >--------------------------------------------------------------
  22. >
  23. >I get the following error:
  24. >
  25. >--------------------------------------------------------------
  26. >error C2664: 'GetDlgItemText' : cannot convert parameter 2 from 'class 
  27. >::CString ' to 'char __far *'
  28. >--------------------------------------------------------------
  29. >
  30. >
  31. >I am using Visual C++, how can I read the text directly into the CString?
  32. >I know that I am doing something REAL STUPID so if you can be of any help-
  33.  
  34. If you are using CWnd::GetDlgItemText(), then the code is quite simple:
  35.  
  36. int msgLen=GetDlgItemText( IDC_EDIT1, callBuf );
  37.  
  38. The compiler error is generated because Visual C++ is trying to match on
  39. one of the two over-rides:
  40.  
  41. int GetDlgItemText( int nID, LPTSTR lpStr, int nMaxCount ) const;
  42. int GetDlgItemText( int nID, CString& rString ) const;
  43.  
  44. (Taken directly from Visual C++ 4.0 help.) You are confusing the compiler
  45. by providing a CString reference *AND* the integer.
  46.  
  47. 'Course, all bets are off if you are _NOT_ using CWnd::GetDlgItemText().
  48. If that's the case, you've got to either allocate a separate char* buffer,
  49. or create a buffer inside the CString object with the GetBuffer() method,
  50. which has the following prototype:
  51.  
  52. LPTSTR GetBuffer( int nMinBufLength );
  53.  
  54. Hope this helps.
  55.  
  56. -- 
  57. ____________________________________________________________
  58. Huw Leonard
  59. "To secure ourselves against defeat lies in our own hands, but the
  60. opportunity of defeating the enemy is provided by the enemy himself.
  61. Hence the saying: One may _know_ how to conquer without being able
  62. to _do_ it." - Sun Tzu, The Art Of War
  63.  
  64.